﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
using NLog;
using NLog.Conditions;

namespace Gollie.NlogExtension
{
	[ConditionMethods]
	public static class Extensions
	{
		private static Regex botPattern = new Regex(((ConfigSectionHandler)ConfigurationManager.GetSection("Gollie.NlogExtension")).BotUserAgents, RegexOptions.Compiled | RegexOptions.IgnoreCase);

		[ConditionMethod("IsBot")]
		public static bool IsBot(string userAgent)
		{
			bool isBot = true;

			if (string.IsNullOrWhiteSpace(userAgent) == false)
			{
				isBot = botPattern.IsMatch(userAgent);

			}

			return isBot;
		}
	}
}
